package org.example.web;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class UrlDemo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String username = "张三";

        //URL编码
        String encode = URLEncoder.encode(username, "utf-8");
        System.out.println(encode);

        //URL解码
        String decode = URLDecoder.decode(encode, "utf-8");
        System.out.println(decode);

        //tomcat
        String decode1 = URLDecoder.decode(encode, "ISO-8859-1");
        System.out.println(decode1);

        //转换为字节
        byte[] bytes = decode1.getBytes("ISO-8859-1");
        for (byte aByte : bytes) {
            System.out.print(aByte + " ");
        }
        System.out.println();
        //将字节数组转为字符串
        String s = new String(bytes, "utf-8");
        System.out.println(s);
    }
}
